
ADC_ConvertedValue(:,1)=savemat(:,14);
ADC_ConvertedValue(:,2)=savemat(:,15);
ADC_ConvertedValue(:,3)=savemat(:,16);
ADC_Value_0_MIN=956;
ADC_Value_1_MIN=902;
ADC_Value_2_MIN=911;
ADC_Value_0_Diff =2214;
ADC_Value_1_Diff =2268;
ADC_Value_2_Diff =2246;
HALL_FeedBack(1) = 3170;
HALL_FeedBack(2) = 3170;
HALL_FeedBack(3) = 3157;
HALL_FeedBack_Rob_Bias=200;
HALL_Value(:,1)=ADC_ConvertedValue(:,1)-ADC_Value_0_MIN;
HALL_Value(:,2)=ADC_ConvertedValue(:,2)-ADC_Value_1_MIN;
HALL_Value(:,3)=ADC_ConvertedValue(:,3)-ADC_Value_2_MIN;	
count=1;
for count = 1:5040
%if count<5040
MAX = 1;
MIN = 1;


				if HALL_FeedBack(MAX)-HALL_Value(count,MAX)>HALL_FeedBack(2)-HALL_Value(count,2)+HALL_FeedBack_Rob_Bias
					MAX=2;
                end
				if HALL_FeedBack(MAX)-HALL_Value(count,MAX)>HALL_FeedBack(3)-HALL_Value(count,3)+HALL_FeedBack_Rob_Bias
					MAX=3;
                end
				if HALL_Value(count,MIN)>HALL_Value(count,2)+HALL_FeedBack_Rob_Bias
					MIN=2;
                end
				if HALL_Value(count,MIN)>HALL_Value(count,3)+HALL_FeedBack_Rob_Bias
					MIN=3;
                end
				Sector(count) = MAX*3+MIN-4;

               switch  Sector(count)
					case 6
                      motor_angle(count) = 120-HALL_Value(2)*60/ ADC_Value_0_Diff;						
					case 7
						motor_angle(count)= 120+HALL_Value(1)*60/ ADC_Value_0_Diff;											
					case 3				
						motor_angle(count)= 0+HALL_Value(3)*60/ ADC_Value_0_Diff;											
					case 5					
						motor_angle(count) = 360-HALL_Value(1)*60/ADC_Value_0_Diff;	
					case 1					
						motor_angle(count)= 240-HALL_Value(3)*60/ADC_Value_0_Diff;												
					case 2				
						motor_angle(count)= 240+HALL_Value(2)*60/ADC_Value_0_Diff;	
               end
end